package cn.boyu.controller;


import cn.boyu.entity.SysRole;
import cn.boyu.query.RoleQuery;
import cn.boyu.result.AjaxResult;
import cn.boyu.service.ISysRoleService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yn
 * @since 2022-11-22
 */
@RestController
@CrossOrigin
@RequestMapping("/sysRole")
public class SysRoleController {

    @Autowired
    private ISysRoleService roleService;

    //查询
    @PostMapping("/query")
    public AjaxResult query(RoleQuery qo){
        IPage<SysRole> page=roleService.queryPage(qo);
        return AjaxResult.success(page);
    }

    //增加 / 修改
    @PostMapping("update")
    public AjaxResult save(SysRole role){
          roleService.saveOrUpdate(role);
          return AjaxResult.success();
    }

    //删除
    @PostMapping("/delete")
    public AjaxResult delete(Long id){
        if (id != null) {
            roleService.removeById(id);
            return AjaxResult.success("操作成功");
        }else{
            return AjaxResult.error("操作失败");
        }
    }
}

